/**************************************************
 * 上海美峰数码科技有限公司(http://www.morefuntek.com)
 * 模块名称: MainWindow
 * 功能描述：
 * 文件名：MainWindow.java
 **************************************************
 */
package com.morefun.sm;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

import com.morefun.actions.AboutAction;
import com.morefun.actions.ExitAcion;
import org.eclipse.swt.widgets.Table;
import org.eclipse.jface.viewers.TableViewer;
import swing2swt.layout.BorderLayout;
import org.eclipse.swt.widgets.Group;

/**
 * 功能描述
 * @author YAOWENHAO
 * @since 2011-10-25 
 * @version 1.0
 */
public class MainWindow extends ApplicationWindow {
	private Action aboutAction;
	private Action exitAction;
	private Table table;

	/**
	 * Create the application window.
	 */
	public MainWindow() {
		super(null);
		createActions();
//		addToolBar(SWT.FLAT | SWT.WRAP);
		addMenuBar();
		addStatusLine();
	}

	/**
	 * Create contents of the application window.
	 * @param parent
	 */
	@Override
	protected Control createContents(Composite parent) {
		Composite container = new Composite(parent, SWT.NONE);
		container.setLayout(new FormLayout());
		
		CTabFolder tabFolder = new CTabFolder(container, SWT.NONE);
		FormData fd_tabFolder = new FormData();
		fd_tabFolder.right = new FormAttachment(100);
		fd_tabFolder.left = new FormAttachment(0);
		fd_tabFolder.bottom = new FormAttachment(100);
		fd_tabFolder.top = new FormAttachment(0);
		tabFolder.setLayoutData(fd_tabFolder);
		
		tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
		
		CTabItem tbtmNewItem = new CTabItem(tabFolder, SWT.NONE);
		tbtmNewItem.setText("在线玩家列表");
		
		Composite composite = new Composite(tabFolder, SWT.NONE);
		tbtmNewItem.setControl(composite);
		composite.setLayout(new BorderLayout(0, 0));
		
		TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
		table = tableViewer.getTable();
		table.setLayoutData(BorderLayout.CENTER);
		
		
		Group grpTest = new Group(composite, SWT.NONE);
		grpTest.setText("Test");
		grpTest.setLayoutData(BorderLayout.SOUTH);
		
		CTabItem tbtmNewItem_1 = new CTabItem(tabFolder, SWT.NONE);
		tbtmNewItem_1.setText("公会列表");
		
		Composite composite_1 = new Composite(tabFolder, SWT.NONE);
		tbtmNewItem_1.setControl(composite_1);
		
		CTabItem tbtmNewItem_2 = new CTabItem(tabFolder, SWT.NONE);
		tbtmNewItem_2.setText("其他");
		
		Composite composite_2 = new Composite(tabFolder, SWT.NONE);
		tbtmNewItem_2.setControl(composite_2);
		
		CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
		tabItem.setText("New Item");
		
		Composite composite_3 = new Composite(tabFolder, SWT.NONE);
		tabItem.setControl(composite_3);
		return container;
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
		aboutAction = new AboutAction(getShell());	
		exitAction = new ExitAcion(this);
	}

	/**
	 * Create the menu manager.
	 * @return the menu manager
	 */
	@Override
	protected MenuManager createMenuManager() {
		MenuManager menuManager = new MenuManager("menu");
		
		MenuManager menuManager_1 = new MenuManager("&File");
		menuManager.add(menuManager_1);
		menuManager_1.add(exitAction);
		
		MenuManager menuManager_2 = new MenuManager("&Edit");
		menuManager.add(menuManager_2);
		
		MenuManager menuManager_3 = new MenuManager("&Help");
		menuManager.add(menuManager_3);
		menuManager_3.add(aboutAction);
		return menuManager;
	}

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			MainWindow window = new MainWindow();
			window.setBlockOnOpen(true);
			window.open();
			Display.getCurrent().dispose();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Configure the shell.
	 * @param newShell
	 */
	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("MY workday!");
		newShell.setSize(500, 500);
	}
}
